home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / noodle / GeneralizedCylinder.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.9 KB  |  231 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  |   Description:
  19.  |      Defines the GeneralizedCylinder class. A nodekit that
  20.  |      makes extruded objects.
  21.  |
  22.  |   Author(s)          : Paul Isaacs
  23.  |
  24. */
  25.  
  26. #ifndef _GENERALIZED_CYLINDER_
  27. #define _GENERALIZED_CYLINDER_
  28.  
  29. #include <Inventor/nodekits/SoBaseKit.h>
  30. #include <Inventor/nodekits/SoSeparatorKit.h>
  31. #include <Inventor/fields/SoSFShort.h>
  32. #include <Inventor/fields/SoSFEnum.h>
  33.  
  34. extern class SoCoordinate3;
  35. extern class SoIndexedFaceSet;
  36. extern class SoSensor;
  37. extern class SoNodeSensor;
  38. extern class SoWriteAction;
  39. extern class NurbMaker;
  40.  
  41. ////////////////////////////////////////////////////////////////////
  42. //    Class: GeneralizedCylinder 
  43. //
  44. // This class constructs a generalized cylinder based on 4 curves:
  45. // The 4 curves are held in the parts:
  46. //  profileCoords, crossSectionCoords, spineCoords, twistCoords.
  47. //
  48. // Users of this class should access only these four parts and the
  49. // 10 fields in order to create different objects.
  50. //
  51. //    The structure of the catalog for this class is:
  52. //
  53. //                       this
  54. //                         |
  55. //                ----------------
  56. //                |              | 
  57. //           "callbackList" "topSeparator"
  58. //                               |
  59. //      -----------------------------------------------------------------
  60. //      |           |            |             |                  |     |
  61. //   "pickStyle" "appearance" "transform" "texture2Transform"     | "childList"
  62. //                                                                |
  63. //   --------------------------------------------------------------
  64. //   |                                          |
  65. //  "inputSwitch"                           "outputSep"
  66. //   |                               ---------------------------------------
  67. //   |                               |(the following appear all in a row)
  68. //   |                          "shapeHints","textureBinding","textureCoords",
  69. //   |                           "texture2", "coords", "faceSet", 
  70. //   |                           "quadMesh", "nurbsSurfaceGroup",
  71. //   |                           "triangleStripSet",
  72. //   |                          "capTextureCoords", "capTextureBinding",
  73. //   |                          "topCapCoords", "topCapFaces",
  74. //   |                          "bottomCapCoords", "bottomCapFaces"
  75. //   |
  76. //   -----------------------------
  77. //   |                |      |   | 
  78. //  "profileCoords"   |      |   |
  79. //      "crossSectionCoords" |   |
  80. //                "spineCoords"  |
  81. //                         "twistCoords"
  82. //
  83. ////////////////////////////////////////////////////////////////////
  84.  
  85. // C-api: prefix=GenCylinder
  86. class GeneralizedCylinder : public SoSeparatorKit {
  87.  
  88.     SO_KIT_HEADER(GeneralizedCylinder);
  89.  
  90.     SO_KIT_CATALOG_ENTRY_HEADER(inputSwitch);
  91.     SO_KIT_CATALOG_ENTRY_HEADER(profileCoords);
  92.     SO_KIT_CATALOG_ENTRY_HEADER(crossSectionCoords);
  93.     SO_KIT_CATALOG_ENTRY_HEADER(spineCoords);
  94.     SO_KIT_CATALOG_ENTRY_HEADER(twistCoords);
  95.     SO_KIT_CATALOG_ENTRY_HEADER(outputGrp);
  96.     SO_KIT_CATALOG_ENTRY_HEADER(shapeHints);
  97.     SO_KIT_CATALOG_ENTRY_HEADER(textureBinding);
  98.     SO_KIT_CATALOG_ENTRY_HEADER(textureCoords);
  99.     SO_KIT_CATALOG_ENTRY_HEADER(texture2);
  100.     SO_KIT_CATALOG_ENTRY_HEADER(coords);
  101.     SO_KIT_CATALOG_ENTRY_HEADER(faceSet);
  102.     SO_KIT_CATALOG_ENTRY_HEADER(quadMesh);
  103.     SO_KIT_CATALOG_ENTRY_HEADER(nurbsSurfaceGroup);
  104.     SO_KIT_CATALOG_ENTRY_HEADER(triangleStripSet);
  105.     SO_KIT_CATALOG_ENTRY_HEADER(capTextureBinding);
  106.     SO_KIT_CATALOG_ENTRY_HEADER(capTextureCoords);
  107.     SO_KIT_CATALOG_ENTRY_HEADER(topCapCoords);
  108.     SO_KIT_CATALOG_ENTRY_HEADER(topCapFaces);
  109.     SO_KIT_CATALOG_ENTRY_HEADER(bottomCapCoords);
  110.     SO_KIT_CATALOG_ENTRY_HEADER(bottomCapFaces);
  111.  
  112.   public:
  113.     GeneralizedCylinder();
  114.  
  115.   public:
  116.  
  117.     //
  118.     // Create a generalized cylinder given the coordinates of its
  119.     // profile, crossSection, spine, and twist.
  120.     //
  121.     void updateSurface();
  122.  
  123.     // Makes a copy of this node as a separator with only the children needed
  124.     // to display it.
  125.     SoSeparator *makeVanillaVersion();
  126.  
  127.     // How should the shape be rendered?
  128.     enum RenderShapeType {
  129.     FACE_SET,
  130.     TRIANGLE_STRIP_SET,
  131.     QUAD_MESH,
  132.     BEZIER_SURFACE,
  133.     CUBIC_SPLINE_SURFACE,
  134.     CUBIC_TO_EDGE_SURFACE
  135.     };
  136.     SoSFEnum  renderShapeType;    
  137.  
  138.     SoSFShort profileClosed;
  139.     SoSFShort crossSectionClosed;
  140.     SoSFShort spineClosed;
  141.     SoSFShort twistClosed;
  142.  
  143.     SoSFShort minNumRows;
  144.     SoSFShort minNumCols;
  145.     SoSFShort withSides;
  146.     SoSFShort withTopCap;
  147.     SoSFShort withBottomCap;
  148.  
  149.     SoSFShort normsFlipped;
  150.     SoSFShort withTextureCoords;
  151.  
  152.     // Used for changing between transform and different types of manip
  153.     void changeTransformType( SoType newType );
  154.  
  155.   SoINTERNAL public:
  156.     static void initClass();
  157.  
  158.   protected:
  159.  
  160.     // detach/attach any sensors, callbacks, and/or field connections.
  161.     // Called by:            start/end of SoBaseKit::readInstance
  162.     // and on new copy by:   start/end of SoBaseKit::copy.
  163.     // Classes that redefine must call setUpConnections(TRUE,TRUE) 
  164.     // at end of constructor.
  165.     // Returns the state of the node when this was called.
  166.     virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE ); 
  167.  
  168.     // Makes it so that the outputGrp and all nodes beneath it do not
  169.     // write out. Since the outputGrp can be re-created from the other 
  170.     // fields, we don't bother writing out all the information, which would 
  171.     // create a larger file.
  172.     virtual void    setDefaultOnNonWritingFields();
  173.  
  174.     NurbMaker *myNurbMaker;
  175.  
  176.     void updateSurroundingManip();
  177.  
  178.   private:
  179.     // destructor
  180.     virtual ~GeneralizedCylinder();
  181.  
  182.     // stuff used by updateSurface
  183.     void loadRow( int rowNum, SbVec3f *newCoords );
  184.     void loadTextureRow( int rowNum, SbVec2f *newCoords );
  185.     void initUpdateInfo();
  186.     void calculateFullProfile();
  187.     void calculateFullCrossSection();
  188.     void getSpineInfo( float paramDist, SbVec3f ¢er, SbRotation &rot );
  189.     SbRotation getSpinePointRotation( int ind0, int ind1, float paramDist );
  190.     void initSpineKeyPointRotations();
  191.     void getTwistInfo( float paramDist, SbRotation &twistRot );
  192.  
  193.     SoIndexedFaceSet *topCapScratchFace;
  194.     SoIndexedFaceSet *bottomCapScratchFace;
  195.  
  196.     SoCoordinate3 *fullProfile;
  197.     SoCoordinate3 *fullCrossSection;
  198.  
  199.     float profileMinY, profileHeight, profileOverHeight;
  200.     float crossSectionMinX, crossSectionWidth;
  201.     float crossSectionMinZ, crossSectionDepth;
  202.     float twistMinY, twistHeight, twistMinAngle, twistMaxAngle;
  203.  
  204.     float spineLength;
  205.     float *spineParamDistances; // parametric distance along spine of each
  206.                     // point on the spine.
  207.     float profileLength;
  208.     float crossSectionLength;
  209.     SbRotation *spineKeyPointRotations;
  210.     int        numAllocedSpineKeyRots;
  211.  
  212.     void changeCurveClosure( char *curveName, SbBool newClosed );
  213.     SbBool profileAlreadyClosed;
  214.     SbBool crossSectionAlreadyClosed;
  215.     SbBool spineAlreadyClosed;
  216.     SbBool twistAlreadyClosed;
  217.  
  218.     void changeWithTextureCoords( SbBool newWith );
  219.     SbBool alreadyWithTextureCoords;
  220.  
  221.     static void fieldsChangedCB(void *data, SoSensor *sens );
  222.     SoNodeSensor *selfSensor;
  223.  
  224.     static void inputChangedCB(void *data, SoSensor *sens );
  225.     SoNodeSensor *inputSensor;
  226. };
  227.  
  228. const double creaseAngle = M_PI/6.0;    // 30 degrees
  229.  
  230. #endif /* _GENERALIZED_CYLINDER_ */
  231.